package com.zhenyi.jiahua.task;

import java.util.List;

import org.joda.time.DateTime;

import com.jfinal.kit.Kv;
import com.jfinal.kit.LogKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.SqlPara;
import com.jiahua.common.model.JhFollow;
import com.zhenyi.jiahua.core.utils.MessageUtils;

/**
 * 预约到时提醒
 * 
 * @author cen
 *
 */
public class JHAppointmentTask implements Runnable {

	@Override
	public void run() {
		Kv kv = Kv.create();
		// kv.set("startTime", new Date());
		kv.set("endTime", new DateTime().plusMinutes(5).toDate());
		SqlPara sqlPara = Db.use("jiahua").getSqlPara("JHFindAppointments", kv);
		List<JhFollow> items = JhFollow.dao.find(sqlPara);
		int size = items.size();
		if (size > 0) {
			LogKit.info("JHAppointmentTask: " + size);
		}
		for (JhFollow jhFollow : items) {
			Long staffId = jhFollow.getStaffId();
			MessageUtils.send(staffId, null, "跟进提醒", jhFollow.getContent());
			jhFollow.setNotiType(JhFollow.TYPE_DONE);
			jhFollow.update();
		}
	}

}
